package seconddemo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Objout {
	public static void main(String[] args) {
		File file=new File("D:\\stu.dat");
		List<Student> stulist=new ArrayList<>();
		stulist.add(new Student("孙悟空", 2000, "花果山"));
		stulist.add(new Student("猪八戒",500,"高老庄"));
		stulist.add(new Student("唐僧", 400, "大唐"));
		try {
			ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(file));
			oos.writeObject(stulist);
			System.out.println("写入成功！");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
